package cn.com.lyb.core.exception;

/**
 * 统一异常枚举
 */
public enum BizExceptionEnum implements IBizException {


    JOB_NAME_REPEAT("job名称重复", "5001"),
    JOB_STATUS_RUNNING("job正在运行中", "5001"),
    WORKFLOW_SELECT("查询工作流失败", "5001")
    ;



    private String code;

    private String message;


    @Override
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public static String getName(String code) {
        for (BizExceptionEnum result : BizExceptionEnum.values()) {
            if (result.getCode().equals(code)) {
                return result.name();
            }
        }
        return null;
    }

    public static String getCode(String name) {
        for (BizExceptionEnum result : BizExceptionEnum.values()) {
            if (result.getMessage().equals(name)) {
                return result.code;
            }
        }
        return null;
    }

    public static String getNameByCode(String code) {
        for (BizExceptionEnum result : BizExceptionEnum.values()) {
            if (result.getCode().equals(code)) {
                return result.getMessage();
            }
        }
        return null;
    }

    public static BizExceptionEnum getByCode(String code) {
        for (BizExceptionEnum result : BizExceptionEnum.values()) {
            if (result.getCode().equals(code)) {
                return result;
            }
        }
        return null;
    }

    BizExceptionEnum(String message, String code) {
        this.message = message;
        this.code = code;
    }


}